interface AreaItem {
    value:string,
    text:string
}

 /**
  *  区域服务
  */
interface IAreaService {
    /**
     * 获取市
     * @param provinceCode 省编号
     */
    getCity(provinceCode:string): ng.IHttpPromise<ListResponse<AreaItem>>;
    /**
     * 获取区
     * @param cityCode 市编号
     */
    getCounty(cityCode:string): ng.IHttpPromise<ListResponse<AreaItem>>;
    /**
     * 获取省
     */
    getArea(): ng.IHttpPromise<ListResponse<AreaItem>>;
}

class areaService implements IAreaService {
    constructor(private http: ng.IHttpService, private route: routeService) {
    }

    getCity(provinceCode:string): ng.IHttpPromise<ListResponse<AreaItem>> {
        return this.http<ListResponse<AreaItem>>({
            method: "GET",
            url: this.route.getUrl("area/city/{{provinceCode}}", {
               provinceCode:provinceCode
            }),
            cache: true
        });
    }

    getCounty(cityCode:string): ng.IHttpPromise<ListResponse<AreaItem>> {
        return this.http<ListResponse<AreaItem>>({
            method: "GET",
            url: this.route.getUrl("area/county/{{cityCode}}", {
               cityCode:cityCode
            }),
            cache: true
        });
    }

    getArea(): ng.IHttpPromise<ListResponse<AreaItem>>{
        return this.http<ListResponse<AreaItem>>({
            method: "GET",
            url: this.route.getUrl("area", {
            }),
            cache: true
        });
    }

}

angular.module('areaService',[]).service("areaService",['$http','routeService',areaService]);

